package cn.edu.zut.qixiang.controller;

import cn.edu.zut.qixiang.service.RealTimeWeatherProducerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 86178
 */
@RestController
@RequestMapping("/api/flink")
@Slf4j
public class FlinkStatusController {

    @Autowired
    private RealTimeWeatherProducerService weatherService;

    /**
     * 检查Flink作业状态
     */
    @GetMapping("/status")
    public Map<String, Object> getFlinkStatus() {
        Map<String, Object> result = new HashMap<>();

        // 简化实现：检查是否有数据流动
        boolean isRunning = weatherService.isFlinkJobRunning();

        result.put("flinkJobRunning", isRunning);
        result.put("lastCheck", LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
        result.put("message", isRunning ?
                "Flink作业运行正常，数据经过实时处理" :
                "Flink作业未运行，前端无数据");

        return result;
    }
}